package vn.edu.hcmut.cse.ai.search.problems.npuzzle;

import java.util.LinkedList;
import java.util.List;
import vn.edu.hcmut.cse.ai.infrastructure.Action;
import vn.edu.hcmut.cse.ai.infrastructure.Actions;

public class NPuzzleActions implements Actions {

    @Override
    public List<Action> getActionList(Object state) {
        List<Action> actionList = new LinkedList<>();

        NPuzzleState puzzleState = (NPuzzleState) state;

        // Check left action
        if (puzzleState.moveLeft()) {
            NPuzzleAction leftAction = new NPuzzleAction(NPuzzleActionType.LEFT);
            actionList.add(leftAction);
            puzzleState.moveRight();
        }

        // Check right action
        if (puzzleState.moveRight()) {
            NPuzzleAction rightAction = new NPuzzleAction(NPuzzleActionType.RIGHT);
            actionList.add(rightAction);
            puzzleState.moveLeft();
        }

        // Check up action
        if (puzzleState.moveUp()) {
            NPuzzleAction upAction = new NPuzzleAction(NPuzzleActionType.UP);
            actionList.add(upAction);
            puzzleState.moveDown();
        }

        // Check down action
        if (puzzleState.moveDown()) {
            NPuzzleAction downAction = new NPuzzleAction(NPuzzleActionType.DOWN);
            actionList.add(downAction);
            puzzleState.moveUp();
        }

        return actionList;
    }

}
